from random import randint
from math import sqrt
import matplotlib.pyplot as plt # Pour afficher l'histogramme

nombre_echantillon = 0
tab_freq_in = [] # Pour afficher l'histogramme
tab_freq_out = [] # Pour afficher l'histogramme
for i in range(200) :
    nombre_succes = 0
    for j in range(100) :
        resultat = randint(1,6)
        if resultat == 1 or resultat == 6 :
            nombre_succes = nombre_succes + 1
    frequence_succes = nombre_succes / 100
    
    
    if 1/3 - 1/sqrt(100) <= frequence_succes <= 1/3 + 1/sqrt(100) :
        tab_freq_in += [frequence_succes] # Pour afficher l'histogramme
        nombre_echantillon = nombre_echantillon + 1
    else : # Pour afficher l'histogramme
        tab_freq_out += [frequence_succes] # Pour afficher l'histogramme
        
## print("proportion des échantillons dans l'intervalle",nombre_echantillon / 200)


# Toute la suite du code sert à afficher l'histogramme

print(tab_freq_in) # Pour afficher l'histogramme
print(tab_freq_out) # Pour afficher l'histogramme
plt.hist([tab_freq_in,tab_freq_out],color=['blue','red'],\
         histtype='bar',bins = 50) # Pour afficher l'histogramme
plt.xticks([i/100 for i in range(0,61,5)])
plt.ylabel('nombres d\'échantillons') # Pour afficher l'histogramme
plt.xlabel('fréquences de succès dans l\'échantillon') # Pour afficher l'histogramme
plt.xlim([0.1, 0.6]) # Pour afficher l'histogramme
plt.savefig("histo.png")
plt.show() # Pour afficher l'histogramme
